package agents.interaction;


import game.constants.ReferenceAgent;
import game.constants.ReferenceSpecialFeature;
import interfaces.impl.HumanInteraction;
import objects.SpetialFeature;
import objects.WorldObject;
import universe.Universe;
import actions.ActionActivateObject;
import actions.ActionPickUpObject;
import actions.ActionXYtoMove;
import extra.ObjectId;
import extra.Position;

public class InteractionPickUpObject extends HumanInteraction{
	
	ObjectId objectToPickUp;
	
	ActionPickUpObject actionPickUpObject; 
	ActionXYtoMove actionXYtoMove;
	
	@Override
	public void initializeParametersList() {
		objectToPickUp= new ObjectId();
		addParameter(objectToPickUp);
		
	}

	@Override
	public void initializeActionList() {
		actionPickUpObject=new ActionPickUpObject();
		addAction(actionPickUpObject);
		
		actionXYtoMove = new ActionXYtoMove();
		addAction(actionXYtoMove);
		
	}

	@Override
	public void initializeSpecialFeatures() {
	
		
	}

	@Override
	public void initializeName() {
		name="Pick Up";
		
	}

	@Override
	public void initializeId() {
		id=ReferenceAgent.AGENT_HUMAN_INTERACTION_PICK_UP_OBJECT;
		
	}

	@Override
	public void updateChild(WorldObject object, Universe universe, double time) {
		
		
		System.out.println("La id del objecto en pick up es : "+objectToPickUp.getObjectId());
		if(objectToPickUp.hasNoId()){
			isActive=false;
			return;
		}
		System.out.println("La id del objecto en pick up es : "+objectToPickUp);
		WorldObject objToPickUp = universe.getObject(objectToPickUp.getObjectId());
		if(objToPickUp==null){
			isActive=false;
			return;
		}
		SpetialFeature canPickUp = objToPickUp.getFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_CAN_PICKUP);
		if(canPickUp==null){
			return;
		}
		
		double distance = Position.DistanceBetween(object.getPosition(), objToPickUp.getPosition());
		if(distance > object.getImageObject().getImageToShow().getWidth()){
			
			actionXYtoMove.setPosition(objToPickUp.getPosition());
			actionXYtoMove.setSource(object);
			actionXYtoMove.setTarget(object);
			universe.setAction(actionXYtoMove);
			return;
		}
		
		actionPickUpObject = new ActionPickUpObject();
		actionPickUpObject.setSource(object);
		actionPickUpObject.setTarget(object);
		actionPickUpObject.setObjetToPickUp(objToPickUp);
		universe.setAction(actionPickUpObject);
		
		ActionActivateObject actionActivateObject = new ActionActivateObject();
		actionActivateObject.setSource(object);
		actionActivateObject.setTarget(objToPickUp);
		universe.setAction(actionActivateObject);
		
		
		System.out.println("genero la accion PICK UP3");

		isActive=false;
		
	}
	
	

}
